@dir=('cases');
$maindir="/data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/GBM";
for($i=0;$i<@dir;$i++)
{
	print "processing $dir[$i]\n";
	$dir=$dir[$i];
	open(WRBUFF,">$maindir/$dir/ambi_runsh_it_$dir") or die " no file exists runshapeit\n";
	print WRBUFF '#! /bin/bash'."\n";
	print WRBUFF '#$ -q 1-day'."\n";
	print WRBUFF '#$ -l h_vmem=10G'."\n";
	print WRBUFF '#$ -M naresh.prodduturi@mayo.edu'."\n";
	print WRBUFF '#$ -m a'."\n";
	print WRBUFF '#$ -V'."\n";
	print WRBUFF '#$ -cwd'."\n";
	$sys="perl /data4/bsi/RandD/Workflow/genotyping_QC_FWD/perl_remove_ambi.pl  $maindir/$dir/maf_lt_015_chr8q24_$dir.haps.gz  $maindir/$dir/ambi_maf_lt_015_chr8q24_$dir.haps.gz $maindir/$dir/ambi.gz";
        print WRBUFF $sys."\n";
	$sys="/data4/bsi/RandD/Workflow/genotyping_1000genome_impute/bin/impute_v2.2.2_x86_64_static/impute2 -use_prephased_g -allow_large_regions -m /data4/bsi/refdata/genetics/1000Genomes/downloaded_data/release/20110521/impute/ALL_1000G_phase1integrated_feb2012_impute/genetic_map_chr8_combined_b37.txt -h /data4/bsi/refdata/genetics/1000Genomes/downloaded_data/release/20110521/impute/ALL_1000G_phase1integrated_feb2012_impute/ALL_1000G_phase1integrated_feb2012_chr8_impute.hap.gz -l /data4/bsi/refdata/genetics/1000Genomes/downloaded_data/release/20110521/impute/ALL_1000G_phase1integrated_feb2012_impute/ALL_1000G_phase1integrated_feb2012_chr8_impute.legend.gz -int 126000000 133000000 -known_haps_g $maindir/$dir/ambi_maf_lt_015_chr8q24_$dir.haps.gz -o $maindir/$dir/impute_8q24_out_ambi";
        print WRBUFF $sys."\n";
        $sys="perl /data4/bsi/RandD/Workflow/genotyping_QC_FWD/perl_check_ambi_snp.pl -a $maindir/$dir/ambi.gz -d $maindir/$dir/impute_8q24_out_ambi -n  $maindir/$dir/impute_8q24_out_ambi_final -m  $maindir/$dir/impute_8q24_out_ambi_indel";
        print WRBUFF $sys."\n";
        $sys="cut -d ' ' -f2- $maindir/$dir/impute_8q24_out_ambi_final |/usr/java/latest/bin/java  -Xmx3000m -jar /data4/bsi/RandD/Workflow/genotyping_1000genome_impute/bin/gprobsmetrics.jar |gzip > $maindir/$dir/beagle.r2.ambi.gz";
        print WRBUFF $sys."\n";
	system("qsub $maindir/$dir/ambi_runsh_it_$dir");
}
